package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.Unknown;

import java.util.Arrays;

/**
 * TODO 未完成
 * <p>
 * 0 1 2 3 4 5 6 7
 * 3 7 2 6 1 5 0 4
 *
 * <p>
 * 0 1 2 3 4 5 6
 * 3 6 2 5 1 4 0
 *
 * @author tzp
 * @since 2020/10/30
 */
public class LC324_1 implements Unknown {
    public void wiggleSort(int[] nums) {
        if (nums.length <= 1) return;
        Arrays.sort(nums);
        int[] target = new int[nums.length];
        int mid = (nums.length - 1) / 2;//3
        for (int i = 0; i < nums.length; i++) {
            if (i <= mid) {
                int index = (mid - i) * 2;
                target[index] = nums[i];
            } else {
                int index = (i - mid) * 2 - 1;
                target[index] = nums[i];
            }
        }
        for (int i = 0; i < nums.length; i++) {
            nums[i] = target[i];
        }
    }

    public static void main(String[] args) {
//        int[] a = {0, 1, 2, 3, 4, 5};
//        int[] a = {1, 1, 2, 1, 2, 2, 1};
//        int[] a = {1, 1, 2, 1, 2, 2, 1, 2};
//        int[] a = {4, 5, 5, 6};
        int[] a = {1, 5, 5, 5, 6, 7};
        new LC324_1().wiggleSort(a);
        System.out.println(Arrays.toString(a));
    }
}
